package ru.spies.entities;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.EAGER;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * The persistent class for the importance database table.
 * 
 */
@Entity
@Table(name="importance")
@NamedQuery(name="Importance.findAll", query="SELECT i FROM Importance i")
public class Importance implements Serializable, ITableClass {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(unique=true, nullable=false)
	private Integer id;

	@Column(nullable=false, length=2147483647)
	private String type;

	//bi-directional many-to-one association to Document
	@OneToMany(mappedBy="importance", fetch = EAGER, cascade = ALL)
	private List<Document> documents;

	//bi-directional many-to-one association to Task
	@OneToMany(mappedBy="importance", fetch = EAGER, cascade = ALL)
	private List<Task> tasks;

	private Object paramForFindQuery=null;
	
	public Importance() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<Document> getDocuments() {
		return this.documents;
	}

	public void setDocuments(List<Document> documents) {
		this.documents = documents;
	}

	public Document addDocument(Document document) {
		getDocuments().add(document);
		document.setImportance(this);

		return document;
	}

	public Document removeDocument(Document document) {
		getDocuments().remove(document);
		document.setImportance(null);

		return document;
	}

	public List<Task> getTasks() {
		return this.tasks;
	}

	public void setTasks(List<Task> tasks) {
		this.tasks = tasks;
	}

	public Task addTask(Task task) {
		getTasks().add(task);
		task.setImportance(this);

		return task;
	}

	public Task removeTask(Task task) {
		getTasks().remove(task);
		task.setImportance(null);

		return task;
	}

	@Override
	public void setParamForFindQuery(Object param) {
		paramForFindQuery=param;		
	}

	@Override
	public Object getParamForFindQuery() {
		return paramForFindQuery;
	}

	@Override
	public ITableClass createThisObject() {
		return new Importance();
	}

	@Override
	public String getQueryForFind() {
		return "SELECT x FROM Importance x WHERE x.id = :param";
	}

}